<template>
	<Echart
		id="leftCenter6"
		:options="options"
		class="left_center_inner"
		ref="daycharts"
	/>
</template>

<script>
import { getgraph } from "@/api/modules/home.js";
import { boxRealtime } from "@/api/modules/energyunit.js";
import { graphic } from "echarts";

export default {
	props: ["id"],
	data() {
		return {
			options: {},
			Ydata: [13, 63, 30, 73, 17, 90, 20],
			dataY2name: [10, 56, 30, 28, 16.0, 3, 10],
		};
	},
	mounted() {
		this.getDate();
	},
	methods: {
		getDate() {
			// 有功功率
			getgraph({ devId: this.id, sampleName: "YC_23" }).then((res) => {
				if (res.code == 200) {
					let xData = [];
					let ygList = [];
					ygList[0] = {
						type: "line",
						symbol: "none",
						data: [],
						name: "储能单元",
					};
					let data = res.data;
					for (let index = 0; index < data.length; index++) {
						let element = data[index];
						xData.push(element.date);
						ygList[0].data.push(
							element.graphHisDTO ? element.graphHisDTO.value.toFixed(2) : ""
						); //实时有效功率
					}
					this.$nextTick(() => {
						// console.log(xData, ygList, this.info.cname);
						this.init(xData, ygList, ["储能单元"]);
					});
				} else {
					this.$Message({
						text: res.msg,
						type: "warning",
					});
				}
			});
		},
		init(xData, yData, dataY2name) {
			this.options = {
				legend: {
					x: "center", //可设定图例在左、右、居中
					y: "10px",
					data: dataY2name,
					textStyle: {
						fontSize: 12,
						color: "#F1F1F3",
					},
				},
				xAxis: {
					type: "category",
					data: xData,
					boundaryGap: false, // 不留白，从原点开始
					splitLine: {
						show: true,
						lineStyle: {
							color: "rgba(31,99,163,.2)",
						},
					},
					axisLine: {
						// show:false,
						lineStyle: {
							color: "rgba(31,99,163,.1)",
						},
					},
					axisLabel: {
						color: "#7EB7FD",
						fontWeight: "500",
					},
				},
				yAxis: {
					name: "单位 ：kW",
					nameTextStyle: {
						color: "#fff",
						fontSize: 12,
					},
					type: "value",
					splitLine: {
						show: true,
						lineStyle: {
							color: "rgba(31,99,163,.2)",
						},
					},
					axisLine: {
						lineStyle: {
							color: "rgba(31,99,163,.1)",
						},
					},
					axisLabel: {
						color: "#7EB7FD",
						fontWeight: "500",
					},
				},
				tooltip: {
					trigger: "axis",
					backgroundColor: "rgba(0,0,0,.6)",
					borderColor: "rgba(147, 235, 248, .8)",
					textStyle: {
						color: "#FFF",
					},
					formatter: function (params) {
						var result = params[0].name + "<br/>";
						params.forEach(function (item) {
							result += item.seriesName + ": " + item.value + "<br/>";
						});
						return result;
					},
				},
				grid: {
					//布局
					show: true,
					left: "40px",
					right: "30px",
					bottom: "10px",
					top: "48px",
					containLabel: true,
					borderColor: "#1F63A3",
				},
				series: yData,
			};
		},
	},
};
</script>
<style lang="scss" scoped></style>
